package com.system.untils;

import java.util.Scanner;

public class FormatOutput {

    public  String formatStringByLength(String str, int maxLength) {
        // 使用 StringBuilder 生成结果
        StringBuilder result = new StringBuilder();

        int length = str.length();
        for (int i = 0; i < length; i += maxLength) {
            // 计算当前段的结束索引
            int end = Math.min(i + maxLength, length);

            // 提取子字符串
            result.append(str, i, end);

            // 如果不是最后一段，则添加换行符
            if (end < length) {
                result.append("\n");
            }
        }

        return result.toString();
    }

    public String multiLineInput() {
        Scanner sc = new Scanner(System.in);
        StringBuilder inputBuilder = new StringBuilder();
        while (true) {
            String line = sc.nextLine();
            if ("END".equalsIgnoreCase(line.trim())) { // 判断是否结束输入
                break;
            }
            inputBuilder.append(line).append(System.lineSeparator());
        }
        return inputBuilder.toString().trim(); // 去除多余的换行符
    }
}
